import { MUSIC_SRC,MUSIC_CURRENT_DETAIL,MUSIC_CONTROLS,MUSIC_NODE,PLAY_ORDER,MUSIC_LIST,MUSIC_CURRENT_TIME } from '../../constant/type'
import { _getSongURL,_getPlayListDetail } from '../../api/recommend'
import {musicList} from '../reducers/music'
import { Toast } from 'react-vant';
//music src和id
export const changeMusicSrc = data =>({type:MUSIC_SRC,data})
export const changeMusicSrcAsync =(id)=>{
    return(dispath)=>{
        _getSongURL(id).then(res=>{
            let src = res ? res.data[0].url:''
            dispath(changeMusicSrc({src,id,data:res.data[0]}))
        }).catch(err=>{
            Toast.info(err.message)
        })
    }
}

//当前播放歌曲的信息
export const changeMusicCurrentDetail = data =>({type:MUSIC_CURRENT_DETAIL,data})

//播放开关
// 初始化是false 暂停
export const changeMusicControls = data =>({type:MUSIC_CONTROLS,data})

//audio-node
export const changeMusicNode = data =>({type:MUSIC_NODE,data})

//0是循环播放 1是顺序播放
export const changePlayOrder = data =>({type:PLAY_ORDER,data})

//当前在播放的歌单
export const changeMusicList = data =>({type:MUSIC_LIST,data})
export const changeMusicListAsync =(id)=>{
    return (dispath)=>{
        _getPlayListDetail(id).then(res=>{
            let data = res.playlist.tracks
            dispath(changeMusicList(data))
        }).catch(err=>{
            Toast.info(err.message)
        })
       
    }
}
//当前播放歌词的时间
export const changeMusicCurrentTime = data =>({type:MUSIC_CURRENT_TIME,data})
